package com.chance.cc.crawler.development.bootstrap.vip;

import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;
import org.junit.Test;

/**
 * @ClassName weipinhui
 * @Description TODO
 * @Author songding
 * @Date 2021/10/9 11:23
 * @Version 1.0
 * 唯品会
 **/
public class VipStart {

    private static String domain = "vip";
    private static String site = "article";
    public static void main(String[] args) {
        article();
    }

    private static void article(){
        String url = "https://category.vip.com/";
                    //https://category.vip.com/
        CrawlerRequestRecord record = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpConfig(HttpConfig.me(domain))
                .httpUrl(url)
                .recordKey(url)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.comment)
                .releaseTime(System.currentTimeMillis())
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*7,null))
                .needParsed(true)
                .needWashed(false)
                .build();
        record.tagsCreator().bizTags().addDomain(domain);
        record.tagsCreator().bizTags().addSite(site);
       // record.tagsCreator().bizTags().addCustomKV("key","鸿星尔克");

        CrawlerRequestRecord keyRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPageItem)
                .httpUrl("http://192.168.1.217:9599/v1/meta/vip/keys?site=searchKw")  //todo 关键字传入
                .requestLabelTag(CrawlerEnum.CrawlerRequestType.supportSource)
                .requestLabelTag(CrawlerEnum.CrawlerRequestType.internalDownload)
                .build();


        DevCrawlerController.builder()
                .crawlerThreadNum(5)
                .triggerInfo(domain,domain,System.currentTimeMillis(),domain)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domain))
                .consoleResultPipeline()
                .fileResultPipeline("F:\\chance_log\\sohu\\article\\data.log",false)
                .requestRecord(record)
                .supportRecord(keyRecord)
                .build("com.chance.cc.crawler.development.scripts.vip")
                .start();
    }

    @Test
    public void test(){
        String regulars = "http[s]*://weibo.com/\\d+/[a-zA-Z0-9\\?\\_\\=]*";
        String url = "http://weibo.com/2210496261/KAfGgcBfm";
        if (url.matches(regulars)){
            System.out.println(1);
        }else{
            System.out.println(2);
        }


    }

}
